/**
 * Created by yuming619 on 2016/10/21.
 */
//rem适配手机大小�
new function (){
    var _self = this;
    _self.width = 640;//�
    _self.fontSize = 100;//
    _self.widthProportion = function(){var p = (document.body&&document.body.clientWidth||document.getElementsByTagName("html")[0].offsetWidth)/_self.width;return p>1?1:p<0.5?0.5:p;};
    _self.changePage = function(){
        document.getElementsByTagName("html")[0].setAttribute("style","font-size:"+_self.widthProportion()*_self.fontSize+"px !important");
    }
    _self.changePage();
    window.addEventListener('resize',function(){_self.changePage();},false);
};
//输入框提示不同内容
function input_alert(html,time){
    if(time ==null){
        time = 2000;
    }
    var float_element = $(".c-float-popWrap")
    var hei = $(window).height()/2
    var top = $(document).scrollTop()+hei-30;
    float_element.css({"top":top+"px"})
    $(".warnMsg").html(html)
    float_element.show()
    setTimeout(function(){
        float_element.hide()
    },time);
}
//改变图标背景色//

//注册监听
function checkConfirm(){
    if(document.getElementById("choose").checked){
        document.getElementById("regedit").removeAttribute("disabled");
        document.getElementById("regedit").style.backgroundColor='rgb(209,0,5)';
        document.getElementById("regedit").style.cursor="pointer";
    }else{
        document.getElementById("regedit").setAttribute("disabled", "disabled");
        document.getElementById("regedit").style.backgroundColor='rgb(94,94,94)';
        document.getElementById("regedit").style.cursor="not-allowed";
    }
}
/*按钮倒计时*/
var timer;
var countdown=60
function settime() {
    if (countdown == 0) {
        document.getElementById("getcode").removeAttribute("disabled");
        document.getElementById("getcode").value="获取验证码";
        $("#getcode").css({"background-color":"#d10005"})
        clearTimeout(timer);
        countdown=60
        return;
    }
    document.getElementById("getcode").setAttribute("disabled", true);
    document.getElementById("getcode").value="重新发送(" + countdown + ")";
    countdown=countdown-1;
    $("#getcode").css({"background-color":"#cccccc"})
    timer = setTimeout("settime()",1000);
}
//改变图标背景色//
function changeBackgroup(x,y){
    document.getElementById(x).style.backgroundColor="rgba(196,25,31,1)";
    document.getElementById(y).style.backgroundColor="rgba(141,141,141,1)";
}
//懒加载
function lazy(){
    $("img.lazy").lazyload({effect: "fadeIn"});
}
/*底部按钮切换*/
function UserChange(x){
    if(x==1){
        document.getElementById("img1").src="images/menu-1.png"
        //document.getElementById("img2").src="images/me-1.png"
        document.getElementById("img3").src="images/me-1.png"
        $("#change1").find("span").addClass("bot_focus");
        //$("#change2").find("span").removeClass("bot_focus");
        $("#change3").find("span").removeClass("bot_focus");
    }else if(x==2){
        document.getElementById("img1").src="images/menu-1.png"
        document.getElementById("img2").src="images/me-2.png"
        document.getElementById("img3").src="images/cart-1.png"
        $("#change1").find("span").removeClass("bot_focus");
        $("#change2").find("span").addClass("bot_focus");
        $("#change3").find("span").removeClass("bot_focus");
    }else if(x==3){
        document.getElementById("img1").src="images/menu-0.png"
       // document.getElementById("img2").src="images/me-1.png"
        document.getElementById("img3").src="images/me-0.png"
        $("#change1").find("span").removeClass("bot_focus");
       // $("#change2").find("span").removeClass("bot_focus");
        $("#change3").find("span").addClass("bot_focus");
    }else if(x==4){
        document.getElementById("img1").src="images/menu-1.png"
        document.getElementById("img2").src="images/me-1.png"
        document.getElementById("img3").src="images/cart-1.png"
        $("#change1").find("span").removeClass("bot_focus");
        $("#change2").find("span").removeClass("bot_focus");
        $("#change3").find("span").removeClass("bot_focus");
    }
}
//接口同步服务器断点动画
function toastHtml(html,show) {
    var float_element = $(".c-float-popWrap")
    if(show==true){
        var hei = $(window).height() / 2
        var top = $(document).scrollTop() + hei - 30;
        float_element.css({"top": top + "px"});
        $(".warnMsg").html(html)
        float_element.show();
    }else{
        float_element.fadeOut();
    }
}
//点击显示隐藏
function click_showadr(a, b, c) {
    if ($(c).val() == 0) {
        $(a).show();
        $(b).show();
        $(c).val(1);
    } else {
        $(a).hide();
        $(b).hide();
        $(c).val(0);
    }
};
//收货地址选择所在区域功能
function  chooseDistrict(Dom,status){
    $("#chooseAddr").find('div').removeClass('active')
    $(Dom).addClass("active");
    var districtChoose = $("#districtChoose").find('.districtChoose');
    switch (status){
        case 1:
            districtChoose.hide();
            districtChoose[0].style.display = 'block';
            break;
        case 2:
            districtChoose.hide();
            districtChoose[1].style.display = 'block';
            break;
        case 3:
            districtChoose.hide();
            districtChoose[2].style.display = 'block';
            break;
        default:
            break;
    }
}
